<?php
//including header.php 
include '../../include/header.php';
//including page.php (It is a class which contain functions)
include '../../libraries/page.php';
//created object for page.php
$page = new page();
session_start();

// checking the session
if (!$_SESSION['username']) {
    header("location:../user/login.php");
}
if ($_GET['q'] == 'logout') {
    $page->user_logout();
    header("location:../user/login.php");
}

// checking the data posted or not
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if ($_POST['chkDel'] == "") {
        $msg = $message[8];
    } else {
        $result = $page->delete("productid", "products", $_POST['chkDel']);
        if ($result) {
            $msg = $message[2];
        } else {
            $msg = $message[0];
        }
    }
}
?>

<!-------------------------------------Navbar---------------------------------->
<div class="navbar">
    <div class="navbar-inner">
        <ul class="nav">
            <li><a href="../groups/groups">Groups</a></li>
            <li class="active"><a href="">Products</a></li>
            <li><a href="../suppliers/suppliers">Suppliers</a></li>
        </ul>
        <a class="brand" href="../../index"  id="right_title"><b style="color:#333;">Inventory</b></a>
        <i class="icon-home" id ="right"></i>
    </div>
</div>
<div style="float:right; margin-right:30px"> <a href="?q=logout">Log out</a></div>

<!----------------------------------Display the result message of deletion--------------------->
<div  align="center"><? echo $msg; ?></div>

<!--------------------------------------content-------------------------------->
<div style="width:960px; margin-left: auto;margin-right: auto; margin-top: 100px;">
   <span><strong style="font-size:22px;">Groups</strong>
      <!---  <a onclick="javascript:checkAll('frmMain', false);" href="javascript:void();" style="float:right">uncheck all</a>
        <a onclick="javascript:checkAll('frmMain', true);" href="javascript:void();" style="float:right; margin-right: 20px;">check all</a></span>-->
		 <a href="javascript:reserveCheck('chkDel[]')" style="float:right">Invert Select</a>
		 <a href="javascript:allCheck('chkDel[]',false)" style="float:right; margin-right: 20px;">Select None</a> 
		 <a href="javascript:allCheck('chkDel[]',true)" style="float:right; margin-right: 20px;">Select All</a></span>
</div>
<br />

<!------------------------------Header Table------------------------------------->
<!----<table class="table table-striped" style="width:500px; margin-left: 12%;margin-top: 50px;">
    <tr><th  colspan="2">Part No</th><th>Part Name</th></tr>

    <tr><th>Old NO</th><td>897082</td><td>Honda brake kit</td></tr>
    <tr><th>New NO</th><td>978456</td><td></td></tr>
</table>------->

<!------------------------------Form------------------------------------->
<form name="frmMain" action="" method="post" OnSubmit="return onDelete();">

    <!------------------------------Details Table------------------------------------->
    <table class="table table-striped" style="width:960px; margin-left: auto;margin-right: auto; ">
        <tr>
            <th></th>
            <th>SL NO</th>
            <th>Name</th>
            <th>Code</th>
			<th>Part No</th>
            <th>Packing</th>
            <th>Price</th>
            <th>Opqty</th>
            <th>Group</th>
			<th>Combination</th>
            <th>Edit</th>

        </tr>

        <?
        //php code to get the data from products table 
        $products = mysql_query("select * from products");
        $id = 0;
        while ($products_data = mysql_fetch_array($products)) {

            $product_id = $products_data['productid'];
            $product_group_id = $products_data['groupid'];
            $name = ucwords(strtolower($products_data['name']));
            $code = $products_data['code'];
			$oldpartno = $products_data['oldpartno'];
			$partno = $products_data['partno'];
            $packing = $products_data['packing'];
            $price = $products_data['price'];
            $opqty = $products_data['opqty'];
            $active = $products_data['active'];
            $groups_actual = mysql_query("select * from groups where groupid = $product_group_id");
            $groups_actual_data = mysql_fetch_array($groups_actual);
            //$groups_actual_id = $groups_actual_data['groupid'];
            $groups_name = ucwords(strtolower($groups_actual_data['name']));
            $id++;
            ?>

            <!-------------------------Dynamic row to display from database--------------------->
            <tr>
                <td><input type="checkbox" name="chkDel[]" id="chkDel<?= $i; ?>" value="<?=$product_id; ?>"></td>
                <td><?=$id; ?></td>
                <td><a href="product_update?id=<?=$product_id; ?>"><?=$name; ?></a></td>
                <td><?=$code; ?></td>
				<td><?=$partno; ?></td>
                <td><?=$packing; ?></td>
                <td><?=$price; ?></td>
                <td><?=$opqty; ?></td>
                <td><?=$groups_name; ?></td>
				<td><a href="search_combination?id=<?=$product_id; ?>">Combination</a></td>
                <td><a href="product_update?id=<?=$product_id; ?>">Edit</a></td>
            </tr>

            <?
            // Closing the loop
        }
        ?>

    </table>
    <!----------------------------CRUD Buttons-------------------------------------->
    <div align="center">
        <a href="product_add"><button class="btn btn-primary" type="button">Add</button></a>
        <button class="btn btn-danger" type="submit">Delete</button>

    </div>
</form>
<?php
//including footer.php
include '../../include/footer.php';
?>
